package com.eusoft.demo.utils;

import com.alibaba.fastjson.JSON;
import com.auth0.jwt.interfaces.DecodedJWT;

import java.util.Base64;
import java.util.HashMap;

/**
 * @author eusoft
 * @since 2021-10-12
 */
public class GetAidUtil {
    public static Integer getByToken(String token){
        DecodedJWT untoken = JWTUtils.getToken(token);
        String payload = untoken.getPayload();
        Base64.Decoder decoder = Base64.getDecoder();
        byte[] bytes = decoder.decode(payload);
        //System.out.println("BASE64解密：" + new String(bytes));
        String str = new String(bytes);
        HashMap hashMap = JSON.parseObject(str, HashMap.class);
        Integer aid = Integer.parseInt(hashMap.get("aid").toString());
        return aid;
    }
}
